
city = [{'code': '410', 'name': '全国'},
 {'code': '010', 'name': '北京'},
 {'code': '020', 'name': '上海'},
 {'code': '030', 'name': '天津'},
 {'code': '040', 'name': '重庆'},
 {'code': '050020', 'name': '广州'},
 {'code': '050090', 'name': '深圳'},
 {'code': '060080', 'name': '苏州'},
 {'code': '060020', 'name': '南京'},
 {'code': '070020', 'name': '杭州'},
 {'code': '210040', 'name': '大连'},
 {'code': '280020', 'name': '成都'},
 {'code': '170020', 'name': '武汉'},
 {'code': '270020', 'name': '西安'}]

workExperiences = [{'code': '1', 'name': '应届生'},
 {'code': '2', 'name': '实习生'},
 {'code': '0$1', 'name': '1年以内'},
 {'code': '1$3', 'name': '1-3年'},
 {'code': '3$5', 'name': '3-5年'},
 {'code': '5$10', 'name': '5-10年'},
 {'code': '10$999', 'name': '10年以上'}]



# header准备

def headers():
    liepin_headers = {
    "Accept":"application/json, text/plain, */*",
    "Accept-Encoding":"gzip, deflate, br",
    "Accept-Language":"zh-CN,zh;q=0.9",
    "Connection":"keep-alive",
    "Content-Length":"487",
    "Content-Type":"application/json;charset=UTF-8;",
    "Cookie":"inited_user=464b5299797bde79a6aeac4e54e72749; __gc_id=fcb411cd19404d6c8519f9289c795f0a; _ga=GA1.1.737936061.1681902650; __uuid=1681902669648.13; need_bind_tel=false; c_flag=92fc82dab3c60b517e05029c26bb865c; imClientId=b5e1273d5cb093f4b435a5bdfa4014a6; imId=b5e1273d5cb093f407ef590fee2a579a; imClientId_0=b5e1273d5cb093f4b435a5bdfa4014a6; imId_0=b5e1273d5cb093f407ef590fee2a579a; new_user=false; XSRF-TOKEN=dh0XXpODSwCKaWPF_5TMDQ; __tlog=1697022022074.43%7C00000000%7C00000000%7Cs_o_007%7Cs_o_007; Hm_lvt_a2647413544f5a04f00da7eee0d5e200=1697022022; hpo_role-sec_project=sec_project_liepin; hpo_sec_tenant=0; UniqueKey=cb5430ca53f7a1c16bc56763ae71c6f2; liepin_login_valid=0; lt_auth=uu0La3ECnA7%2F5nba2zFbta1O2o%2BsAzrM8S4LgUgC1YW6XqXg4P%2FmQAOHqrEG%2BCoIqxshIfUzMLb3Muj8y3JK7UMS%2BVGnlZ6utf6k0HsDUeVtIMW2vezHg%2FXUQp0lkkAA8nJbpEIL%2BVzO; user_roles=0; user_photo=5f8fa3baf6d1ab58476f324908u.png; user_name=%E5%90%B4%E8%8C%B5%E8%8C%B5; inited_user=464b5299797bde79a6aeac4e54e72749; imApp_0=1; _ga_54YTJKWN86=GS1.1.1697022021.9.1.1697023068.0.0.0; __session_seq=12; __uv_seq=12; Hm_lpvt_a2647413544f5a04f00da7eee0d5e200=1697023069; fe_im_opened_pages=_1697023070436; fe_im_socketSequence_new_0=5_5_5; fe_im_connectJson_0=%7B%220_cb5430ca53f7a1c16bc56763ae71c6f2%22%3A%7B%22socketConnect%22%3A%224%22%2C%22connectDomain%22%3A%22liepin.com%22%7D%7D; __tlg_event_seq=60",
    "Host":"api-c.liepin.com",
    "Origin":"https://www.liepin.com",
    "Referer":"https://www.liepin.com/",
    "Sec-Ch-Ua":"\Google Chrome\";v=\"119\", \"Chromium\";v=\"119\", \"Not?A_Brand\";v=\"24\"",
    "Sec-Ch-Ua-Mobile":"?0",
    "Sec-Ch-Ua-Platform":"\Windows\"",
    "Sec-Fetch-Dest":"empty",
    "Sec-Fetch-Mode":"cors",
    "Sec-Fetch-Site":"same-site",
    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36",
    "X-Client-Type":"web",
    "X-Fscp-Bi-Stat":"{\"location\": \"https://www.liepin.com/zhaopin/?currentPage=0&pageSize=40&city=050090&dq=050090&pubTime=&key=%E4%BA%A7%E5%93%81%E7%BB%8F%E7%90%86&suggestTag=&otherCity=&industry=&scene=condition&skId=n6tbyab50hqfp57f2938dc8nxy9k5btb&fkId=n6tbyab50hqfp57f2938dc8nxy9k5btb&ckId=n6tbyab50hqfp57f2938dc8nxy9k5btb&sfrom=search_job_pc&suggestId=\"}",
    "X-Fscp-Fe-Version":None,
    "X-Fscp-Std-Info":"{\"client_id\": \"40108\"}",
    "X-Fscp-Trace-Id":"41aafc33-4b97-4094-a7bf-c0858337bf9f",
    "X-Fscp-Version":"1.1",
    "X-Requested-With":"XMLHttpRequest",
    "X-Xsrf-Token":"AC-8dG1sTSqXIEek6c65WQ"
}
    return liepin_headers


# 准备城市code
def choose_city(city_name):
    for i in city:
        if i['name'] == city_name:
            return i['code']

# 准备工作经验code
def choose_WE(工作经验):
    for i in workExperiences:
        if i['name'] == 工作经验:
            return i['code']
        
# 准备公司规模code
def choose_WE(公司规模):
    for i in workExperiences:
        if i['name'] == 公司规模:
            return i['code']
        
# 准备payload
def request_payload(城市,关键词,工作经验,公司规模):
    payload = {
        "data": {
            "mainSearchPcConditionForm": {
                "city": choose_city(城市),
                "dq": choose_city(城市),
                "pubTime": "",
                "currentPage": "0",
                "pageSize": 40,
                "key": 关键词,
                "suggestTag": "",
                "workYearCode": choose_WE(工作经验),
                "compId": "",
                "compName": "",
                "compTag": "",
                "industry": "",
                "salary": "",
                "jobKind": "",
                "compScale": "",
                "compKind": "",
                "compStage": "",
                "eduLevel": ""
            },
            "passThroughForm": {
                "scene": "condition",
                "skId": "geq5b0qsi9umzbhn0oojbi2j8v8qu2bb",
                "fkId": "geq5b0qsi9umzbhn0oojbi2j8v8qu2bb",
                "ckId": "y2jy1uvl2gar8xipyemg77rijoomop78",
                "suggest": None
            }
        }
    }
    return payload